{% extends "real_estate_app/base.html" %}

{% block head %}
<script src="/admin-media/js/jquery.min.js" type="text/javascript"></script>
<script src="/admin-media/js/jquery.init.js" type="text/javascript"></script>
<script src="{{ MEDIA_REAL_ESTATE }}js/fullcalendar/fullcalendar.min.js"></script>
<script src="{{ MEDIA_REAL_ESTATE }}js/moment.js" ></script>
<link rel="stylesheet" href="{{ MEDIA_REAL_ESTATE }}js/fullcalendar/fullcalendar.css" />
<link rel="stylesheet" href="{{ MEDIA_URL }}bimoveis/css/custom-fullcalendar.css" />
<link media="print" rel="stylesheet" href="{{ MEDIA_REAL_ESTATE }}js/fullcalendar/fullcalendar.print.css" />

<script type="text/javascript">
	(function($) {
		$(document).ready(function() {
			
			$calendar=$('#calendar').fullCalendar({
				header: {
					left: 'prev,next today',
					center: 'title',
					right: 'month,agendaWeek,agendaDay'
				},
				monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
				monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
				dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
				dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb'],
				buttonText: {
					prev: '&nbsp;&#9668;&nbsp;',
					next: '&nbsp;&#9658;&nbsp;',
					prevYear: '&nbsp;&lt;&lt;&nbsp;',
					nextYear: '&nbsp;&gt;&gt;&nbsp;',
					today: 'Hoje',
					month: 'Mês',
					week: 'Semana',
					day: 'Dia'
				},		
				titleFormat: {
					month: 'MMMM yyyy',
					week: "d [ yyyy]{ '&#8212;'[ MMM] d MMM yyyy}",
					day: 'dddd, d MMM, yyyy'
				},
				columnFormat: {
					month: 'ddd',
					week: 'ddd d/M',
					day: 'dddd d/M'
				},

				allDaySlot: false,
				slotMinutes:60,
				axisFormat: 'H:mm',
				timeFormat: {
					'': 'H:mm',
					agenda: 'H:mm{ - H:mm}'
				},
				selectable: true,
				{% if property %}
				dayClick: function(date, allDay, jsEvent, view) {
						date_format=moment(date).format('YYYY-MM-DD HH:mm:ss')
						window.location="{% url visitcalendar-create-object property|slugify %}?date_visit="+date_format
						$('#calendar').fullCalendar('unselect');
				},
				{% endif %}
				events: function(tart, end, callback) {
					$.ajax({
            				url: "{%if property %}{% url visitcalendar-list-json property|slugify %} {% else %} {% url visitcalendar-list-json-index %} {% endif %}",
            				dataType: 'json',
            				success: function(doc) {
            					var events = [];
            					$(doc).each(function(){
            						events.push({
            							title:$(this).attr('title'),
            							start:$(this).attr('start'),
            							allDay: false,
            						});

            					})
            					callback(events);
            				}
			        });
				}
			});
			$('.fc-button-month').click(function() { $calendar.fullCalendar('refetchEvents')})
			$('.fc-button-agendaWeek').click(function() { $calendar.fullCalendar('refetchEvents')})
			$('.fc-button-agendaDay').click(function() { $calendar.fullCalendar('refetchEvents')})
		})
	})(django.jQuery);
</script>
{% endblock %}


{% block content_main %}
	<div id="calendar" style="width:500px;"></div>
{% endblock %}